<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>提现明细列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/layuiadmin/style/admin.css" media="all">
    <style>
        .layui-table-body .layui-table-cell {
            height: 50px; line-height: 50px;
        }
        .layui-laypage .layui-laypage-curr .layui-laypage-em{ background-color: #1E9FFF; }
        .layui-form-checked[lay-skin=primary] i{border-color: #1E9FFF!important;background-color: #1E9FFF;color:#fff;}
        .layui-form-checkbox[lay-skin=primary]:hover i{border-color:#1E9FFF;color:#fff}
        p.money {
            color: #f8a20f;
            font-size: 30px;
            font-weight: bold;
            height: 35px;
            line-height: 35px;
            padding: 5px 0;
            padding-bottom: 15px;
        }
    </style>
</head>
<body>

<div class="layui-fluid" id="LAY-component-grid-speed-dial">
    <div class="layui-row layui-col-space1">
        <div class="layui-col-sm12">
            <!-- 填充内容 -->
            <div class="layui-card">
                <div class="layui-card-header">友情提示</div>
                <div class="layui-card-body" >
                    <p>1、提现审核时间为工作日的9：00-17：20</p>
                    <p>2、每天最多提现10次，每笔金额最少300元，最多100万元。</p>
                    <p>3、为了提高打款速度，现将最低提现金额调整为300元请知晓。</p>
                </div>
            </div>
        </div>
    </div>

    <div class="layui-row layui-col-space1">
        <div class="layui-col-xs4">
            <!-- 填充内容 -->
            <div class="layui-card">
                <div class="layui-card-body" style="text-align: center;">
                    <p>账户余额<span style="cursor:pointer;" title="截止昨天账户可提现的金额"><img src="" alt=""></span></p>
                    <p class="money">￥{$balance}</p>
                </div>
            </div>
        </div>
        <div class="layui-col-xs4">
            <div class="layui-card">
                <div class="layui-card-body" style="text-align: center;">
                    <p>累计提现<span style="cursor:pointer;" title="截至目前的所有申请提现金额（包括提现已打款和已审未打款）"><img src="" alt=""></span></p>
                    <p class="money">￥{$withdrawal_amount}</p>
                </div>
            </div>
        </div>
        <div class="layui-col-xs4">
            <div class="layui-card">
                <div class="layui-card-body" style="text-align: center;">
                    <p>累计收入<span style="cursor:pointer;" title="截止昨天的所有分成收入"><img src="" alt=""></span></p>
                    <p class="money">￥{$commission_amount}</p>
                </div>
            </div>
        </div>
    </div>

    <div class="layui-row">

        <div class="layui-col-md12">
            <div class="layui-card">

                <div lay-filter="listSearch" class="layui-form layui-card-header layuiadmin-card-header-auto" style="height:auto;padding:10px 15px;">

                    <div class="layui-form-item">

                        <div class="layui-inline">
                            <select name="status">
                                <option value="0">全部状态</option>
                                <option value="1">待审核</option>
                                <option value="2">已审未打款</option>
                                <option value="3">已打款</option>
                            </select>
                        </div>

                        <div class="layui-inline">
                            <input type="text" id="dayStart" name="start_date" placeholder="请输入开始日期" autocomplete="off" class="layui-input">
                        </div>

                        <div class="layui-inline">
                            <input type="text" id="dayEnd" name="end_date" placeholder="请输入截止日期" autocomplete="off" class="layui-input">
                        </div>

                        <div class="layui-inline">
                            <button class="layui-btn layui-btn-normal layuiadmin-btn-admin" lay-submit lay-filter="LAY-list-front-search">
                                <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                            </button>
                            <button type="button" class="layui-btn layui-btn-primary" lay-submit lay-filter="LAY-reset">重置</button>
                        </div>

                    </div>

                </div>

                <div class="layui-card-body">

                    <div style="padding-bottom: 10px;">
                        <button class="layui-btn layui-btn-normal layuiadmin-btn-useradmin" data-type="add">申请提现</button>
                    </div>

                    <table id="LAY-list-manage" lay-filter="LAY-list-manage"></table>

                    <script type="text/html" id="table-tool">
                        <a class="layui-btn layui-btn-normal layui-btn-sm" lay-event="preview">查看信息</a>
                    </script>

                </div>

            </div>
        </div>

    </div>

</div>



<script src="/static/layuiadmin/layui/layui.js"></script>
<script>

    layui.use('laydate', function () {
        var $ = layui.$;
        var laydate = layui.laydate;

        var nowTime = new Date().valueOf();
        var start = laydate.render({
            elem: '#dayStart',
            type: 'date',
            max: nowTime,
            done: function (value, date) {
                endMax = end.config.max;
                end.config.min = date;
                end.config.min.month = date.month - 1;
            }
        });
        var end = laydate.render({
            elem: '#dayEnd',
            type: 'date',
            max: nowTime,
            done: function (value, date) {
                if ($.trim(value) == '') {
                    var curDate = new Date();
                    date = {
                        'date': curDate.getDate(),
                        'month': curDate.getMonth() + 1,
                        'year': curDate.getFullYear()
                    };
                }
                start.config.max = date;
                start.config.max.month = date.month - 1;
            }
        });
    });

    layui.config({
        base: '/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','table','admin'], function(){

        var $ = layui.$
            ,form = layui.form
            ,table = layui.table;

        //监听搜索
        form.on('submit(LAY-list-front-search)', function(data){
            var field = data.field;
            //执行重载
            table.reload('LAY-list-manage', {
                where: field
                ,page: {
                    curr: 1  // 将页码重置为第一页
                }
            });
        });

        form.on('submit(LAY-reset)', function(data){
            form.val("listSearch", {
                "start_date": "",
                "end_date": "",
                "agent_id": "0",
                "status": "0"
            });
            form.render();
            table.reload('LAY-list-manage', {
                where: {"start_date": "", "end_date": "","status": "0","agent_id": "0"}
                ,page: {
                    curr: 1  // 将页码重置为第一页
                }
            });
        });

        //书籍管理
        table.render({
            elem: '#LAY-list-manage'
            ,url: "{:url('Withdrawal/list_data')}" //模拟接口
            ,autoSort: false
            ,cols: [[
                {field: 'id', width: 100, title: 'ID', sort: true, align:'center'}
                ,{field: 'agent_name', title: '代理商', align:'center'}
                ,{field: 'money', title: '申请金额（元）', align:'center'}
                ,{field: 'state', title: '状态', align:'center'}
                ,{field: 'settlement_date', title: '结算日期', align:'center'}
                ,{field: 'create_time', title: '日期', align:'center'}
                ,{title: '操作', width: 240, align:'center', fixed: 'right', toolbar: '#table-tool'}
            ]]
            ,page: true
            ,limit: 30
            ,height: 'full-220'
            ,text: '对不起，加载出现异常！'
        });

        table.on('tool(LAY-list-manage)', function(obj){

            if(obj.event === 'preview'){

                layer.open({
                    type: 2
                    ,title: '提现信息预览'
                    ,content: "{:url('Withdrawal/examine')}?id="+obj.data.id
                    ,maxmin: true
                    ,area: ['580px', '740px']
                    ,btn: ['关闭']
                    ,btnAlign: 'c'
                    ,yes: function(index, layero){
                        layer.close(index); //关闭弹层
                    }
                });

            }

        });

        var active = {
            add: function(){
                layer.open({
                    type: 2
                    ,title: '申请提现'
                    ,content: "{:url('Withdrawal/add')}"
                    ,maxmin: true
                    ,area: ['580px', '560px']
                    ,btn: ['确定', '取消']
                    ,yes: function(index, layero){
                        var iframeWindow = window['layui-layer-iframe'+ index]
                            ,submitID = 'LAY-data-add-submit'
                            ,submit = layero.find('iframe').contents().find('#'+ submitID);

                        //监听提交
                        iframeWindow.layui.form.on('submit('+ submitID +')', function(data){

                            submit.attr('disabled',true);

                            $.ajax({
                                url:"{:url('Withdrawal/add')}",
                                type:"post",
                                dataType: "json",
                                data:data.field,
                                async:true,
                                success: function(rs){
                                    if(rs['code'] == 100){

                                        layer.msg(rs['msg'],function () {
                                            layer.close(index); //关闭弹层
                                            window.location.reload();
                                        });

                                    }else{
                                        layer.msg(rs['msg']);
                                    }
                                    submit.attr('disabled',false);
                                    return false;
                                }
                            });
                        });

                        submit.trigger('click');
                    }
                });
            }
        };

        $('.layuiadmin-btn-useradmin').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    });
</script>
</body>
</html>